package com.wash.shoes.controller.pc;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.BannerPo;
import com.wash.shoes.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ljg
 * @since 2024-12-12
 */
@Api(tags = {"PC-系统的banner"})
@RestController
@RequestMapping({"/banner/", "/dev-api/banner"})
public class BannerController {

    @Autowired
    BannerService bannerService;

    @ApiOperation("获取列表")
    @PostMapping("/list")
    public R<Page<BannerPo>> pageList(@RequestBody BannerPo bannerPo) {
        Page<BannerPo> page = bannerService.pageList(bannerPo);
        return R.ok(page);
    }

    @ApiOperation("修改新增,有id为修改没有为新增")
    @PostMapping("/saveUpdate")
    public R<String> add(@RequestBody BannerPo bannerPo) {
        if (ObjectUtil.isEmpty(bannerPo.getId())) {
            bannerPo.setStatus(1);
            bannerService.save(bannerPo);
        } else {
            bannerService.updateById(bannerPo);
        }
        return R.ok();
    }

    @ApiOperation("逻辑删除修改 status为0")
    @GetMapping("/deleteByStatus")
    public R<BannerPo> deleteByStatus(String theId) {

        BannerPo bannerPo = bannerService.getById(theId);
        bannerPo.setStatus(0);
        bannerService.updateById(bannerPo);
        return R.ok(bannerPo);
    }

    @ApiOperation("获取详情")
    @GetMapping("/getDetailById")
    public R<BannerPo> getDetailById(String theId) {
        BannerPo bannerPo = bannerService.getById(theId);
        return R.ok(bannerPo);
    }

}

